package com.ruoyi.web.controller.mstn;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.mstnExcel.ExcelUtils;
import com.ruoyi.system.domain.excelImport.MstnCatalystsImport;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MstnCatalysts;
import com.ruoyi.system.service.IMstnCatalystsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 催化剂Controller
 * 
 * @author ruoyi
 * @date 2024-07-10
 */
@RestController
@RequestMapping("/catalyzer/catalyzerData")
public class MstnCatalystsController extends BaseController
{
    @Autowired
    private IMstnCatalystsService mstnCatalystsService;

    /**
     * 查询催化剂列表
     */
    @PreAuthorize("@ss.hasPermi('catalyzer:catalyzerData:list')")
    @GetMapping("/list")
    public TableDataInfo list(MstnCatalysts mstnCatalysts)
    {
        startPage();
        List<MstnCatalysts> list = mstnCatalystsService.selectMstnCatalystsList(mstnCatalysts);
        return getDataTable(list);
    }

    /**
     * 导出催化剂列表
     */
    @PreAuthorize("@ss.hasPermi('catalyzer:catalyzerData:export')")
    @Log(title = "催化剂", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MstnCatalysts mstnCatalysts)
    {
        List<MstnCatalysts> list = mstnCatalystsService.selectMstnCatalystsList(mstnCatalysts);
        ExcelUtil<MstnCatalysts> util = new ExcelUtil<MstnCatalysts>(MstnCatalysts.class);
        util.exportExcel(response, list, "催化剂数据");
    }

    /**
     * 获取催化剂详细信息
     */
    @PreAuthorize("@ss.hasPermi('catalyzer:catalyzerData:query')")
    @GetMapping(value = "/{catalystsId}")
    public AjaxResult getInfo(@PathVariable("catalystsId") Long catalystsId)
    {
        return success(mstnCatalystsService.selectMstnCatalystsByCatalystsId(catalystsId));
    }

    /**
     * 新增催化剂
     */
    @PreAuthorize("@ss.hasPermi('catalyzer:catalyzerData:add')")
    @Log(title = "催化剂", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MstnCatalysts mstnCatalysts)
    {
        return toAjax(mstnCatalystsService.insertMstnCatalysts(mstnCatalysts));
    }

    /**
     * 修改催化剂
     */
    @PreAuthorize("@ss.hasPermi('catalyzer:catalyzerData:edit')")
    @Log(title = "催化剂", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MstnCatalysts mstnCatalysts)
    {
        return toAjax(mstnCatalystsService.updateMstnCatalysts(mstnCatalysts));
    }

    /**
     * 删除催化剂
     */
    @PreAuthorize("@ss.hasPermi('catalyzer:catalyzerData:remove')")
    @Log(title = "催化剂", businessType = BusinessType.DELETE)
	@DeleteMapping("/{catalystsIds}")
    public AjaxResult remove(@PathVariable Long[] catalystsIds)
    {
        return toAjax(mstnCatalystsService.deleteMstnCatalystsByCatalystsIds(catalystsIds));
    }


    /**
     * 通用上传请求
     */
    @PostMapping("/upload")
    public AjaxResult uploadFile(MultipartFile file) throws Exception
    {
        try
        {
            List<MstnCatalystsImport> array = ExcelUtils.readMultipartFile(file, MstnCatalystsImport.class);
            for (MstnCatalystsImport mstnCatalystsImport : array) {
                mstnCatalystsService.insertMstnCatalysts(mstnCatalystsImport.toMstnCatalysts());
            }
            return success();
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }
}
